package com.miaostars.apakey.checks;

import com.miaostars.apakey.Apakey;
import com.miaostars.apakey.utils.PlayerData;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;

import java.util.HashMap;
import java.util.Map;

public class XRayChecks {
    
    private final Apakey plugin;
    private final Map<Material, Integer> valuableBlocks = new HashMap<>();
    
    public XRayChecks(Apakey plugin) {
        this.plugin = plugin;
        initializeValuableBlocks();
    }
    
    private void initializeValuableBlocks() {
        valuableBlocks.put(Material.DIAMOND_ORE, 10);
        valuableBlocks.put(Material.EMERALD_ORE, 10);
        valuableBlocks.put(Material.GOLD_ORE, 5);
        valuableBlocks.put(Material.IRON_ORE, 3);
        valuableBlocks.put(Material.REDSTONE_ORE, 2);
        valuableBlocks.put(Material.LAPIS_ORE, 4);
        valuableBlocks.put(Material.ANCIENT_DEBRIS, 15);
    }
    
    public boolean checkXRay(Player player, PlayerData data, Block block) {
        if (!plugin.getConfigManager().getConfig().getBoolean("checks.xray.enabled")) {
            return false;
        }
        
        if (player.hasPermission("apakey.bypass")) {
            return false;
        }
        
        if (!valuableBlocks.containsKey(block.getType())) {
            return false;
        }
        
        // Check if player is mining valuable blocks at an abnormal rate
        int value = valuableBlocks.get(block.getType());
        data.addXRayValue(value);
        
        long timeWindow = plugin.getConfigManager().getConfig().getLong("checks.xray.time-window", 60000); // 1 minute
        int maxValue = plugin.getConfigManager().getConfig().getInt("checks.xray.max-value", 100);
        
        if (data.getXRayValue(timeWindow) > maxValue) {
            return true;
        }
        
        return false;
    }
}
